<template>
	<view>

		<!-- 搜索历史 -->
		<view style="padding-left: 20rpx; padding-top: 45rpx;font-size: 30rpx; color: #696964;margin-bottom: 10rpx;">
			搜索历史
		</view>

		<!-- 历史记录 -->
		<searchList :historyList="historyList"></searchList>
		
	</view>
</template>

<script>
	import searchList from "@/components/common/search-history.vue"
	export default {
		components:{
			searchList
		},
		data() {
			
			return {
				searchStr:"",
				historyList:[]
			}
		},
		// 监听原生搜索框输入事件
		onNavigationBarSearchInputChanged(e) {
			this.searchSrt = e
		},
		
		// 监听原生搜索按钮点击事件
		onNavigationBarButtonTap(e) {
			this.historyList.push(this.searchSrt.text)
			// 写入缓存
			uni.setStorage({
				key:"search_history",
				data:this.historyList
			})
		},
		onShow() {
			try {
			    var cacheValue = uni.getStorageSync('search_history');
			    if (cacheValue) {
					
						for (let i=0; i< cacheValue.length; i++){
							this.historyList.push(cacheValue[i])
						}
					
			    }
			} catch (e) {
			    // error
				console.log(e)
			}
		},
		methods: {
			// 搜索后历史记录添加
			
		}
	}
</script>

<style>

</style>
